package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface SetmealMapper {

    /**
     * 根据分类id查询套餐的数量
     * @param id
     * @return
     */
    @Select("select count(id) from setmeal where category_id = #{categoryId}")
    Integer countByCategoryId(Long id);
   /* 插入套餐数据*/
   @AutoFill(value = OperationType.INSERT)
   @Options(useGeneratedKeys = true, keyProperty = "id")
@Insert("insert into setmeal(category_id, name, price, description, image, create_time, update_time, create_user, update_user) " +
        "VALUES(#{categoryId},#{name},#{price},#{description},#{image},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void insertSetmeal(Setmeal setmeal);

    Page<SetmealVO> page(SetmealPageQueryDTO setmealPageQueryDTO);
@Select("select s.*,c.name as categoryName from setmeal s left join category c on s.category_id = c.id where s.id = #{id}")
    SetmealVO getByIdsetmeal(Long id);
@AutoFill(value = OperationType.UPDATE)
    void updateSetmeal(Setmeal setmeal);
@AutoFill(value = OperationType.UPDATE)
@Update("update setmeal set status = #{status} where id =#{id}")
    void updeteStatus(Integer status, Long id);

    void deleteBatchSetmeal(List<Long> ids);

    Integer selectsetmealStatus(Long id);
/*根据分类id查询套餐*/


    List<Setmeal> list(Setmeal setmeal);
//根据套餐id查询套餐数据
    @Select("select * from setmeal where id =#{setmealId}")
    Setmeal selectSeatmeal(Long setmealId);




    /**
     * 根据条件统计套餐数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
